package com.hg.design.behavior.memento.biancheng.ex3;

public class PrototypeMemento {
    public static void main(String[] args) {
        OriginatorPrototype or = new OriginatorPrototype();
        PrototypeCaretaker cr = new PrototypeCaretaker(4);
        or.setState("S0");
        System.out.println("初始状态:" + or.getState());
        cr.setMemento(or.createMemento()); //保存状态
        System.out.println("---------------------------");

        or.setState("S1");
        System.out.println("新的状态:" + or.getState());
        cr.setMemento(or.createMemento()); //保存状态
        System.out.println("---------------------------");

        or.setState("S2");
        System.out.println("新的状态:" + or.getState());
        cr.setMemento(or.createMemento()); //保存状态
        System.out.println("---------------------------");

        or.setState("S3");
        System.out.println("新的状态:" + or.getState());
        System.out.println("---------------------------");

        or.restoreMemento(cr.getMemento()); //恢复状态
        System.out.println("恢复状态:" + or.getState());
        System.out.println("---------------------------");

        or.setState("S4");
        System.out.println("新的状态:" + or.getState());
        cr.setMemento(or.createMemento()); //保存状态
        System.out.println("---------------------------");

        or.setState("S5");
        System.out.println("新的状态:" + or.getState());
        cr.setMemento(or.createMemento()); //保存状态
        System.out.println("---------------------------");

        or.setState("S6");
        System.out.println("新的状态:" + or.getState());
        cr.setMemento(or.createMemento()); //保存状态
        System.out.println("---------------------------");

        or.setState("S7");
        System.out.println("新的状态:" + or.getState());
        cr.setMemento(or.createMemento()); //保存状态
        System.out.println("---------------------------");

        or.restoreMemento(cr.getMemento()); //恢复状态
        System.out.println("恢复状态:" + or.getState());
        System.out.println("---------------------------");

        or.restoreMemento(cr.getMemento()); //恢复状态
        System.out.println("恢复状态:" + or.getState());
        System.out.println("---------------------------");

        or.restoreMemento(cr.getMemento()); //恢复状态
        System.out.println("恢复状态:" + or.getState());
        System.out.println("---------------------------");

        or.setState("S8");
        System.out.println("新的状态:" + or.getState());
        cr.setMemento(or.createMemento()); //保存状态
        System.out.println("---------------------------");

        or.setState("S9");
        System.out.println("新的状态:" + or.getState());
        cr.setMemento(or.createMemento()); //保存状态
        System.out.println("---------------------------");

        or.setState("S10");
        System.out.println("新的状态:" + or.getState());
        cr.setMemento(or.createMemento()); //保存状态
        System.out.println("---------------------------");

        or.setState("S11");
        System.out.println("新的状态:" + or.getState());
        cr.setMemento(or.createMemento()); //保存状态
        System.out.println("---------------------------");

        or.restoreMemento(cr.getMemento()); //恢复状态
        System.out.println("恢复状态:" + or.getState());
        System.out.println("---------------------------");

        or.restoreMemento(cr.getMemento()); //恢复状态
        System.out.println("恢复状态:" + or.getState());
        System.out.println("---------------------------");

        or.restoreMemento(cr.getMemento()); //恢复状态
        System.out.println("恢复状态:" + or.getState());
        System.out.println("---------------------------");

        or.restoreMemento(cr.getMemento()); //恢复状态
        System.out.println("恢复状态:" + or.getState());
        System.out.println("---------------------------");

        or.restoreMemento(cr.getMemento()); //恢复状态
        System.out.println("恢复状态:" + or.getState());
        System.out.println("---------------------------");

        or.restoreMemento(cr.getMemento()); //恢复状态
        System.out.println("恢复状态:" + or.getState());
        System.out.println("---------------------------");
    }
}
